---
title: "Analysis"
author: "Ksiazkiewicz et al."
date: "2024-02-27"
output:
  pdf_document: default
  word_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
library(knitr)
library(texreg)

data2=read.csv("~/[adjust the path as needed]/df22.csv")
data=read.csv("~/[adjust the path as needed]/df23.csv")
data$Race=forcats::fct_relevel(data$Race, "White", "Black", "Latinx", "Indigenous", "Other")
```


# Race, Partisanship, Experience Study 2: Table 1
```{r, out.width=9}
round(mean(data2$age, na.rm = TRUE),1)
round(prop.table(table(data2$man)),3)*100
round(prop.table(table(data2$woman)),3)*100

round(prop.table(table(data2$white)),2)*100
round(prop.table(table(data2$black)),2)*100
round(prop.table(table(data2$latino)),2)*100
round(prop.table(table(data2$asian)),2)*100
round(prop.table(table(data2$native)),2)*100

round(mean(data2$income, na.rm = TRUE),1)
round(mean(data2$edu, na.rm = TRUE),1)
round(prop.table(table(data2$party)),3)*100
round(mean(data2$relig, na.rm = TRUE),1)

round(prop.table(table(data2$exp1)),2)*100
round(prop.table(table(data2$exp_f)),2)*100
round(prop.table(table(data2$Q68)),2)*100

round(prop.table(table(data2$exp2)),2)*100
round(prop.table(table(data2$Q71)),2)*100
round(prop.table(table(data2$Q74)),2)*100

round(prop.table(table(data2$exp3)),2)*100
```

# Race, Partisanship, Experience Study 3: Table 1
```{r, out.width=9}
round(mean(data$age, na.rm = TRUE),1)
round(prop.table(table(data$man)),3)*100
round(prop.table(table(data$woman)),3)*100

round(prop.table(table(data$Race)),2)*100

round(mean(data$income, na.rm = TRUE),1)
round(mean(data$edu, na.rm = TRUE),1)
round(prop.table(table(data$party)),3)*100
round(mean(data$relig, na.rm = TRUE),2)
round(prop.table(table(data$children_yes)),3)*100

round(prop.table(table(data$exp1)),2)*100
round(prop.table(table(data$exp_f)),2)*100
round(prop.table(table(data$Q68)),2)*100

round(prop.table(table(data$exp2)),2)*100
round(prop.table(table(data$Q71)),2)*100
round(prop.table(table(data$Q74)),2)*100

round(prop.table(table(data$exp3)),2)*100
```



#GSPQ Final 16 Regression Study 3: Table 2, Table 3, Table 4
```{r, out.width=9}
race_vars2 <- c("Race")
exp_vars2 <-c("exp")
genknow_vars2 <-c("genknow1", "genknow2", "genknow3")
party_vars2 <-c("party")

gspq_vars4 <- c("age", "man", "income", "edu", "relig", "children_yes", "risk", "concern", "trust", "pc2_final", "pc3_final")
gspq_vars5 <- c("age", "man", "income", "edu", "relig", "children_yes", "risk", "concern", "trust", "pc1_final", "pc3_final")
gspq_vars6 <- c("age", "man", "income", "edu", "relig", "children_yes", "risk", "concern", "trust", "pc1_final", "pc2_final")

all_vars6 <- c(race_vars2, exp_vars2, genknow_vars2, party_vars2, gspq_vars4)
all_vars7 <- c(race_vars2, exp_vars2, genknow_vars2, party_vars2, gspq_vars5)
all_vars8 <- c(race_vars2, exp_vars2, genknow_vars2, party_vars2, gspq_vars6)

dependent_vars6 <- c("pc1_final")
dependent_vars7 <- c("pc2_final")
dependent_vars8 <- c("pc3_final")

models7 <- list()
models8 <- list()
models9 <- list()

for (dep_var in dependent_vars6) {
  models7[[paste0(dep_var, "_1")]] <- lm(as.formula(paste(dep_var, "~", paste(race_vars2, collapse="+"))), data=data)
  models7[[paste0(dep_var, "_2")]] <- lm(as.formula(paste(dep_var, "~", paste(exp_vars2, collapse="+"))), data=data)
  models7[[paste0(dep_var, "_3")]] <- lm(as.formula(paste(dep_var, "~", paste(genknow_vars2, collapse="+"))), data=data)
  models7[[paste0(dep_var, "_4")]] <- lm(as.formula(paste(dep_var, "~", paste(party_vars2, collapse="+"))), data=data)
  models7[[paste0(dep_var, "_5")]] <- lm(as.formula(paste(dep_var, "~", paste(gspq_vars4, collapse="+"))), data=data)
  models7[[paste0(dep_var, "_6")]] <- lm(as.formula(paste(dep_var, "~", paste(all_vars6, collapse="+"))), data=data)
}

for (dep_var in dependent_vars7) {
  models8[[paste0(dep_var, "_1")]] <- lm(as.formula(paste(dep_var, "~", paste(race_vars2, collapse="+"))), data=data)
  models8[[paste0(dep_var, "_2")]] <- lm(as.formula(paste(dep_var, "~", paste(exp_vars2, collapse="+"))), data=data)
  models8[[paste0(dep_var, "_3")]] <- lm(as.formula(paste(dep_var, "~", paste(genknow_vars2, collapse="+"))), data=data)
  models8[[paste0(dep_var, "_4")]] <- lm(as.formula(paste(dep_var, "~", paste(party_vars2, collapse="+"))), data=data)
  models8[[paste0(dep_var, "_5")]] <- lm(as.formula(paste(dep_var, "~", paste(gspq_vars5, collapse="+"))), data=data)
  models8[[paste0(dep_var, "_6")]] <- lm(as.formula(paste(dep_var, "~", paste(all_vars7, collapse="+"))), data=data)
}

for (dep_var in dependent_vars8) {
  models9[[paste0(dep_var, "_1")]] <- lm(as.formula(paste(dep_var, "~", paste(race_vars2, collapse="+"))), data=data)
  models9[[paste0(dep_var, "_2")]] <- lm(as.formula(paste(dep_var, "~", paste(exp_vars2, collapse="+"))), data=data)
  models9[[paste0(dep_var, "_3")]] <- lm(as.formula(paste(dep_var, "~", paste(genknow_vars2, collapse="+"))), data=data)
  models9[[paste0(dep_var, "_4")]] <- lm(as.formula(paste(dep_var, "~", paste(party_vars2, collapse="+"))), data=data)
  models9[[paste0(dep_var, "_5")]] <- lm(as.formula(paste(dep_var, "~", paste(gspq_vars6, collapse="+"))), data=data)
  models9[[paste0(dep_var, "_6")]] <- lm(as.formula(paste(dep_var, "~", paste(all_vars8, collapse="+"))), data=data)
}

pc1f_model_list <- lapply(models7, function(x) x)
pc2f_model_list <- lapply(models8, function(x) x)
pc3f_model_list <- lapply(models9, function(x) x)

texreg(pc1f_model_list, booktabs = TRUE, dcolumn = TRUE, no.margin = TRUE, fontsize = "small", custom.coef.names = c("Intercept", "Black identity", "Latinx identity", "Indigenous identity", "Other racial identity", "Experience with testing", "Genetic knowledge (Genes)", "Genetic knowledge (Health)", "Genetic knowledge (Heritability)", "Independent", "Republican", "Age", "Man", "Income", "Education", "Religiosity", "Parent",  "Risk", "Concern", "Trust", "GUIP (inaccuracy)", "GUIP (privacy)"), include.ci = FALSE, ci.level = 0.95, custom.model.names = c("Identity", "Experience", "GenKnow", "Party", "Others", "All"))

texreg(pc2f_model_list, booktabs = TRUE, dcolumn = TRUE, no.margin = TRUE, fontsize = "small", custom.coef.names = c("Intercept", "Black identity", "Latinx identity", "Indigenous identity", "Other racial identity", "Experience with testing", "Genetic knowledge (Genes)", "Genetic knowledge (Health)", "Genetic knowledge (Heritability)", "Independent", "Republican", "Age", "Man", "Income", "Education", "Religiosity", "Parent",  "Risk", "Concern", "Trust", "GUIP (utility)", "GUIP (privacy)"), include.ci = FALSE, ci.level = 0.95, custom.model.names = c("Identity", "Experience", "GenKnow", "Party", "Others", "All"))

texreg(pc3f_model_list, booktabs = TRUE, dcolumn = TRUE, no.margin = TRUE, fontsize = "small", custom.coef.names = c("Intercept", "Black identity", "Latinx identity", "Indigenous identity", "Other racial identity", "Experience with testing", "Genetic knowledge (Genes)", "Genetic knowledge (Health)", "Genetic knowledge (Heritability)", "Independent", "Republican", "Age", "Man", "Income", "Education", "Religiosity", "Parent",  "Risk", "Concern", "Trust", "GUIP (utility)", "GUIP (inaccuracy)"), include.ci = FALSE, ci.level = 0.95, custom.model.names = c("Identity", "Experience", "GenKnow", "Party", "Others", "All"))

dependent_vars <- list(dependent_vars6, dependent_vars7, dependent_vars8)
independent_vars <- list(all_vars6, all_vars7, all_vars8)
models33 <- list()
for (i in 1:length(dependent_vars)) {
  model <- lm(data = data, formula = paste(dependent_vars[[i]], "~", paste(independent_vars[[i]], collapse = " + ")))
  models33[[i]] <- model
}
texreg(models33, booktabs = TRUE, dcolumn = TRUE, no.margin = TRUE, fontsize = "small", custom.coef.names = c("Intercept", "Black identity", "Latinx identity", "Indigenous identity", "Other racial identity", "Experience with testing", "Genetic knowledge (Genes)", "Genetic knowledge (Health)", "Genetic knowledge (Heritability)", "Independent", "Republican", "Age", "Man", "Income", "Education", "Religiosity", "Parent",  "Risk", "Concern", "Trust", "GUIP (inaccuracy)", "GUIP (privacy)", "GUIP (utility)"), include.ci = FALSE, ci.level = 0.95, custom.model.names = c("GUIP (positive)", "GUIP (pointless)", "GUIP (privacy)"))
```



#Willingness Regression (GSPQ_final16) Study 3: Table 5, Table 6
```{r, out.width=9}
race_vars <- c("white", "black", "latino", "asian", "native")
demo_vars <- c("age", "man", "income", "edu", "party", "relig")
relevant_vars <- c("exp", "genknow1", "genknow2", "genknow3", "gendeter", "risk", "concern", "trust", "justifiable", "disgust")
all_vars <- c(race_vars, demo_vars, relevant_vars)

dependent_vars2 <- c("will1", "will2", "will3", "will4")

gspq_final16 <- c("pc1_final", "pc2_final", "pc3_final")
all_vars9 <- c(gspq_final16, "Race", "exp", "genknow1", "genknow2", "genknow3", "party", "age", "man", "income", "edu", "relig", "children_yes", "risk", "concern", "trust")

models3 <- list()
for (i in 1:length(dependent_vars2)) {
  formula <- paste(dependent_vars2[i], "~", paste(gspq_final16, collapse = " + "))
  model <- lm(formula, data = data)
  models3[[i]] <- model
}
texreg(models3, booktabs=TRUE, dcolumn= TRUE, no.margin = TRUE, fontsize = "small", custom.coef.names = c("Intercept", "GSPQ (positive)", "GSPQ (pointless)", "GSPQ (privacy)"), include.ci = FALSE, ci.level = 0.95, custom.model.names = c("Physician", "Medical researchers", "Pharmaceutical companies", "Law enforcement"))


models3w <- list()
for (i in 1:length(dependent_vars2)) {
  formula <- paste(dependent_vars2[i], "~", paste(all_vars9, collapse = " + "))
  model <- lm(formula, data = data)
  models3w[[i]] <- model
}
texreg(models3w, booktabs=TRUE, dcolumn= TRUE, no.margin = TRUE, fontsize = "small", custom.coef.names = c("Intercept", "GSPQ (utility)", "GSPQ (inaccuracy)", "GSPQ (privacy)", "Black identity", "Latinx identity", "Indigenous identity", "Other racial identity", "Experience with testing", "Genetic knowledge (Genes)", "Genetic knowledge (Health)", "Genetic knowledge (Heritability)", "Independent", "Republican", "Age", "Man", "Income", "Education", "Religiosity", "Parent",  "Risk", "Concern", "Trust"), include.ci = FALSE, ci.level = 0.95, custom.model.names = c("Physician", "Medical researchers", "Pharmaceutical companies", "Law enforcement"))


models333 <- list()
for (dep_var in dependent_vars2) {
  models333[[paste0(dep_var, "_1")]] <- lm(as.formula(paste(dep_var, "~", paste(gspq_final16, collapse="+"))), data=data)
  models333[[paste0(dep_var, "_2")]] <- lm(as.formula(paste(dep_var, "~", paste(all_vars9, collapse="+"))), data=data)
}
```


#Genetic testing participation: Table 7, 8
```{r, out.width=9}
#by genetic testing experience (asked to participate and participated)
asked=subset(data, Q89==1)

#by genetic testing experience (not asked to participate but willing)
notasked=subset(data, Q89==0)

#asked to participate in genomic research and participated (90 = exp3)
#not asked to participate in genomic research but willing to participate (91)

dependent_varsra <- c("exp3")
dependent_varsrn <- c("Q91")

all_varsan <- c(gspq_final16, "Race", "exp1", "exp2", "genknow1", "genknow2", "genknow3", "party", "age", "man", "income", "edu", "relig", "children_yes", "risk", "concern", "trust")

modelsra <- list()
for (i in 1:length(dependent_varsra)) {
  modelsra[[paste0(dependent_varsra, "_1")]] <- lm(as.formula(paste(dependent_varsra, "~", paste(gspq_final16, collapse="+"))), data=asked)
  modelsra[[paste0(dependent_varsra, "_2")]] <- lm(as.formula(paste(dependent_varsra, "~", paste(race_vars2, collapse="+"))), data=asked)
  modelsra[[paste0(dependent_varsra, "_3")]] <- lm(as.formula(paste(dependent_varsra, "~", paste(all_varsan, collapse="+"))), data=asked)
}

modelsrn <- list()
for (i in 1:length(dependent_varsrn)) {
modelsrn[[paste0(dependent_varsrn, "_1")]] <- lm(as.formula(paste(dependent_varsrn, "~", paste(gspq_final16, collapse="+"))), data=notasked)
  modelsrn[[paste0(dependent_varsrn, "_2")]] <- lm(as.formula(paste(dependent_varsrn, "~", paste(race_vars2, collapse="+"))), data=notasked)
  modelsrn[[paste0(dependent_varsrn, "_3")]] <- lm(as.formula(paste(dependent_varsrn, "~", paste(all_varsan, collapse="+"))), data=notasked)
}

texreg(modelsra, booktabs=TRUE, dcolumn= TRUE, no.margin = TRUE, fontsize = "small", custom.coef.names = c("Intercept", "GUIP (utility)", "GSPQ (pointless)", "GSPQ (privacy)", "Black", "Latinx", "Indigenous", "Other race", "Experience (DTC)", "Experience (medical test)", "Genetic knowledge (Genes)", "Genetic knowledge (Health)", "Genetic knowledge (Heritability)", "Independent", "Republican", "Age", "Man", "Income", "Education", "Religiosity", "Parent",  "Risk", "Concern", "Trust"), include.ci = FALSE, ci.level = 0.95, custom.model.names = c("GSPQ", "Race", "All"))

texreg(modelsrn, booktabs=TRUE, dcolumn= TRUE, no.margin = TRUE, fontsize = "small", custom.coef.names = c("Intercept", "GSPQ (positive)", "GSPQ (pointless)", "GSPQ (privacy)", "Black", "Latinx", "Indigenous", "Other race", "Experience (DTC)", "Experience (medical test)", "Genetic knowledge (Genes)", "Genetic knowledge (Health)", "Genetic knowledge (Heritability)", "Independent", "Republican", "Age", "Man", "Income", "Education", "Religiosity", "Parent",  "Risk", "Concern", "Trust"), include.ci = FALSE, ci.level = 0.95, custom.model.names = c("GSPQ", "Race", "All"))
```


# Single-item
```{r, out.width=9}
#How concerned are you regarding the privacy of your genetic/DNA information
single_privacy=data$Q122
single_security=data$Q123
pc3_final=data$pc3_final

cor.test(single_privacy, single_security)
cor.test(single_privacy, pc3_final)
cor.test(single_security, pc3_final)

lm200=lm(will~Q122, data=data)
summary(lm200)
lm201=lm(will~pc3_final, data=data)
summary(lm201)
lm202=lm(will~Q122+pc3_final, data=data)
summary(lm202)

lm203=lm(Q122~Race, data=data)
summary(lm203)
lm205=lm(Q122~Race+exp+genknow1+genknow2+genknow3+party++age+man+income+edu+relig+children_yes+risk+concern+trust, data=data)
summary(lm205)

lm206=lm(Q123~Race+exp+genknow1+genknow2+genknow3+party++age+man+income+edu+relig+children_yes+risk+concern+trust, data=data)
summary(lm206)
```




